package com.projectcost.system.controller;

import com.projectcost.common.annotation.Log;
import com.projectcost.common.core.controller.BaseController;
import com.projectcost.common.core.domain.AjaxResult;
import com.projectcost.common.core.page.TableDataInfo;
import com.projectcost.common.enums.BusinessType;
import com.projectcost.common.utils.poi.ExcelUtil;
import com.projectcost.system.domain.ProjectManagement;
import com.projectcost.system.service.IProjectManagementService;
import org.apache.shiro.authz.annotation.RequiresPermissions;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Controller;
import org.springframework.ui.ModelMap;
import org.springframework.web.bind.annotation.*;

import java.util.List;

/**
 * 项目管理Controller
 *
 * @author projectcost
 * @date 2024-11-17
 */
@Controller
@RequestMapping("/system/managementsh")
public class ProjectManagementShController extends BaseController {
    private String prefix = "system/managementsh";

    @Autowired
    private IProjectManagementService projectManagementService;

    @RequiresPermissions("system:managementsh:view")
    @GetMapping()
    public String management() {
        return prefix + "/managementsh";
    }

    /**
     * 查询项目管理列表
     */
    @PostMapping("/list")
    @ResponseBody
    public TableDataInfo list(ProjectManagement projectManagement) {
        startPage();
        List<ProjectManagement> list = projectManagementService.selectProjectManagementList(projectManagement);
        return getDataTable(list);
    }

    /**
     * 导出项目管理列表
     */
    @Log(title = "项目管理", businessType = BusinessType.EXPORT)
    @PostMapping("/export")
    @ResponseBody
    public AjaxResult export(ProjectManagement projectManagement) {
        List<ProjectManagement> list = projectManagementService.selectProjectManagementList(projectManagement);
        ExcelUtil<ProjectManagement> util = new ExcelUtil<ProjectManagement>(ProjectManagement.class);
        return util.exportExcel(list, "项目管理数据");
    }

    /**
     * 新增项目管理
     */
    @GetMapping("/add")
    public String add() {
        return prefix + "/add";
    }

    /**
     * 新增保存项目管理
     */
    @Log(title = "项目管理", businessType = BusinessType.INSERT)
    @PostMapping("/add")
    @ResponseBody
    public AjaxResult addSave(ProjectManagement projectManagement) {
        projectManagement.setStatus("已上传");
        return toAjax(projectManagementService.insertProjectManagement(projectManagement));
    }

    /**
     * 修改项目管理
     */
    @GetMapping("/edit/{id}")
    public String edit(@PathVariable("id") Long id, ModelMap mmap) {
        ProjectManagement projectManagement = projectManagementService.selectProjectManagementById(id);
        mmap.put("projectManagement", projectManagement);
        return prefix + "/edit";
    }

    /**
     * 修改保存项目管理
     */
    @Log(title = "项目管理", businessType = BusinessType.UPDATE)
    @PostMapping("/edit")
    @ResponseBody
    public AjaxResult editSave(ProjectManagement projectManagement) {
        return toAjax(projectManagementService.updateProjectManagement(projectManagement));
    }

    /**
     * 删除项目管理
     */
    @Log(title = "项目管理", businessType = BusinessType.DELETE)
    @PostMapping("/remove")
    @ResponseBody
    public AjaxResult remove(String ids) {
        return toAjax(projectManagementService.deleteProjectManagementByIds(ids));
    }
}
